package com.example.attempt.service.impl;

import com.example.attempt.entity.Student;
import com.example.attempt.mapper.StudentMapper;
import com.example.attempt.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Override
    //查询所有学生
    public List<Student> queryAll(){
        return studentMapper.queryAll();
    }

    @Override
    //添加学生
    public int addStudent(Student student){
        studentMapper.addStudent(student);
        return 1;
    }

//    @Override
//    //批量添加学生
//    public int addStudents(List<Student> students) {
////        Student student = new Student();
//        for(int i = 0; i< students.size(); i++){
//            Student student = students.get(i);
////            student.setSid(student.getSid());
//            studentMapper.addStudent(student);
//        }
//        return 1;
//    }

    @Override
    //根据学号查询学生信息
    public Student queryById(String sid){
        return studentMapper.queryById(sid);
    }

    @Override
    //根据姓名查询学生信息
    public List<Student> queryByName(String sname){
        return studentMapper.queryByName(sname);
    }

    @Override
    //获取学生数
    public int getNum(){
        return studentMapper.getNum();
    }

    @Override
    //删除学生
    public void deleteStudent(String sid) {
        studentMapper.deleteStudent(sid);
    }

    @Override
    public Student queryByIdAndP(String sid, String spwd){
        return studentMapper.queryByIdAndP(sid, spwd);
    }

}
